package example.controller;


import example.entity.User;
import example.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@Api(value = "UserApi", description = "用户管理")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "单个查询")
    @GetMapping("/query")
    public Object query(@ApiParam(value = "id", required = true) @RequestParam() String id) {
        return userService.getById(id);
    }

    @ApiOperation(value = "单个删除")
    @PostMapping("/delete")
    public Object delete(@ApiParam(value = "id", required = true) @RequestParam() String id) {
        return userService.removeById(id);
    }

    @ApiOperation(value = "单个新增")
    @PostMapping("/insert")
    public Object create(@RequestBody User user) {
        return userService.save(user);
    }

    @ApiOperation(value = "单个更新")
    @PostMapping("/update")
    public Object update(@RequestBody User user) {
        return userService.updateById(user);
    }
}

